﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace COFE.Core.Lister
{
    /// <summary>
    /// Optional, add additional methods to check whether a path exists.
    /// </summary>
    public interface IPrimaryDirectoryLister2 : IPrimaryDirectoryLister
    {
        /// <summary>
        /// Return whether the specified file or directory (which is represent by isFolder) is exists in this FileSystem.
        /// </summary>
        /// <param name="path"></param>
        /// <param name="isFolder">Whether the entries is a directory.</param>
        /// <returns>Whether the entries is found.</returns>
        bool Exists(string path, out bool isFolder);
        
    }

    public static class IPrimaryDirectoryLister2Extension
    {
        /// <summary>
        /// Return whether the specified file is exists in this FileSystem.
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static bool FileExists(this IPrimaryDirectoryLister2 ip2, string path)
        {
            bool isFolder;
            return ip2.Exists(path, out isFolder) && !isFolder;
        }

        /// <summary>
        /// Whether the specified directory is exists in this FileSystem.
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static bool DirectoryExists(this IPrimaryDirectoryLister2 ip2, string path)
        {
            bool isFolder;
            return ip2.Exists(path, out isFolder) && isFolder;
        }

        /// <summary>
        /// Whether the specified entries is exist or not.
        /// </summary>
        /// <param name="ip2"></param>
        /// <param name="path"></param>
        /// <returns></returns>
        public static bool Exists(this IPrimaryDirectoryLister2 ip2, string path)
        {
            bool isFolder;
            return ip2.Exists(path, out isFolder);
        }
    }
}
